﻿-- Ajout d'un filtre sur la colonne IsVersioned dans la vue vw_medianamik_ModifiedNode Correction d'un bug sur la vue des ManytoMany
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_medianamik_ModifiedNode]'))
BEGIN
	DECLARE @q1 NVARCHAR(MAX)
    SELECT @q1 = 'ALTER VIEW [dbo].[vw_medianamik_ModifiedNode] AS
WITH NullRevisions AS (SELECT     NodeId, CultureName
							 FROM          dbo.medianamik_NodePropertyValue AS npv
							 WHERE      (Revision IS NULL)
							 GROUP BY NodeId, CultureName)
	, NodeCulture AS (Select ni.NodeId, ni.CultureName
					FROM dbo.medianamik_NodeInstance as ni
					INNER JOIN NullRevisions nr ON nr.NodeId = ni.NodeId AND nr.CultureName IN (ni.CultureName, '''')
					GROUP BY ni.NodeId, ni.CultureName)
	SELECT  n.*, nc.CultureName,  t.path as TypePath    FROM NodeCulture nc
	inner join medianamik_node n on nc.nodeid = n.nodeid
	inner join medianamik_type t on t.typeid = n.typeid
	where n.isdeleted = 0 and t.isVersioned = 1'
	EXEC sp_executesql @q1
END
SET ANSI_NULLS OFF
SET QUOTED_IDENTIFIER OFF